package Day26;

import com.thoughtworks.xstream.XStream;

public class Demo07 {
    public static void main(String[] args) {
        Person p = new Person();
        p.setAge(18);
        p.setName("张小呆");
        //XStream的使用
        //  创建XStream对象
        XStream x = new XStream();
        //  修改某个类型生成的节点（可选的，默认为包名.类名）
        x.alias("Person",Person.class);
        //  传入对象开始生成
        String xml = x.toXML(p);
        System.out.println(xml);
        //<Person>
        //  <name>张小呆</name>
        //  <age>18</age>
        //</Person>
    }
}
class Person{
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
